﻿using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Vision.Abstractions.Events;
using Vision.Abstractions.Processing;
using Vision.Devices;

namespace Vision.UI.ViewModels
{
    public partial class ControlViewModel: ObservableObject
    {

        private readonly FakeCamera _camera;
        private readonly IImageProcessingParameters _processingParameters;

        [RelayCommand]
        public async void Start()
        {
            await _camera.InitializeAsync();
            await _camera.StartAsync(CancellationToken.None);
        }

        [RelayCommand]
        public async void Stop()
        {
           await _camera.StopAsync(CancellationToken.None);
        }

        private int _cameraDelay;
        public int CameraDelay
        {
            get => _cameraDelay;
            set
            {
                if (SetProperty(ref _cameraDelay, value))
                {
                    _camera.SetDelay(value);
                }
            }
        }

        // 图像处理参数 - 直接绑定到共享的参数服务
        public double BinaryThreshold
        {
            get => _processingParameters.BinaryThreshold;
            set
            {
                _processingParameters.BinaryThreshold = value;
                OnPropertyChanged();
            }
        }

        public double EdgeThreshold
        {
            get => _processingParameters.EdgeThreshold;
            set
            {
                _processingParameters.EdgeThreshold = value;
                OnPropertyChanged();
            }
        }

        public ControlViewModel(FakeCamera camera, IImageProcessingParameters processingParameters)
        {
            _camera = camera;
            _processingParameters = processingParameters;
            _cameraDelay = _camera.Delay;
        }



    }
}
